<?php


namespace App\Models;


class ProductSpec extends BaseModel
{
    protected $table = 'products_spec';

    public static function getSpec($product_id)
    {
        $where = [
            ['product_id', '=', $product_id]
        ];
        $spce = self::where($where)
            ->select('id as spce_id', 'product_id', 'name', 'content')
            ->get()
            ->toArray();
        foreach ($spce as &$val) {
            $val['content'] = unserialize($val['content']);
        }
        return $spce;
    }

    //组合规格参数
    public static function getSpecItem($product_id)
    {
        $specItem = self::where('product_id', $product_id)
            ->select('id as spec_id','name as spec_name')
            ->get()
            ->toArray();
        foreach ($specItem as &$val) {
            $val['spec_item'] = ProductSpecItem::getItemBySpecId($val['spec_id']);
        }
        return  serialize($specItem);
    }
}